package com.gusti.mensajes.controller.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gusti.mensajes.controller.IMessageController;
import com.gusti.mensajes.services.IMessageService;
import com.gusti.mensajes.util.ConstantsUtil;
import com.gusti.mensajes.util.MessageResponse;

/**
 * 
 * @author gusti
 *
 */
@Controller
public class MessageController implements IMessageController {

	@Autowired
	IMessageService messageService;

	@RequestMapping(value = "/new/user/{userName}", method = RequestMethod.GET)
	@ResponseBody
	public MessageResponse newUser( @PathVariable("userName") String userName ) {
		
		return messageService.newUser( userName );
	}

	@RequestMapping(value = "/new/message/{fromUserUuid}/{toUserUuid}/{messageText}", method = RequestMethod.GET)
	@ResponseBody
	public MessageResponse newMessage( @PathVariable("fromUserUuid") String fromUserUuid, @PathVariable("toUserUuid") String toUserUuid, @PathVariable("messageText") String messageText ) {
		
		return messageService.newMessage( fromUserUuid, toUserUuid, messageText );
	}

	@RequestMapping(value = "/list/users", method = RequestMethod.GET)
	@ResponseBody
	public MessageResponse listUsers() {
		
		return messageService.listUsers();
	}
	
	@RequestMapping(value = "/list/conversation/{userUuid}", method = RequestMethod.GET)
	@ResponseBody
	public MessageResponse listConversation( @PathVariable("userUuid") String userUuid ) {
		
		return messageService.listConversation( userUuid );
	}

	@RequestMapping(value = "/view/conversation/{conversationId}/{userUuid}", method = RequestMethod.GET)
	@ResponseBody
	public MessageResponse viewConversation( @PathVariable("conversationId") String conversationId, @PathVariable("userUuid") String userUuid ) {
		
		return messageService.viewConversation( conversationId, userUuid );
	}

	@RequestMapping(value = "/404", method = RequestMethod.GET)
	@ResponseBody
	public MessageResponse error404() {
		MessageResponse messageResponse = new MessageResponse();
		messageResponse.setErrorMsg( ConstantsUtil.ERROR_404 );
		return messageResponse;
	}
	
	@RequestMapping(value = "/500", method = RequestMethod.GET)
	@ResponseBody
	public MessageResponse error500() {
		MessageResponse messageResponse = new MessageResponse();
		messageResponse.setErrorMsg( ConstantsUtil.ERROR_500 );
		return messageResponse;
	}
}
